Assignment

Due 1 February 2007. Submission details to follow.
  1. DNA (represented as a string over the alphabet 'ACGT') consists of two strands, one the reverse complement of the other: swap A's with T's, C's with G's and then reverse the result. The reverse complement of ACCGGGTTTT is AAAACCCGGT. Assume that the variable dna holds such a sequence. Write a python snippet to generate dna's reverse complement. Hint: remember dir is your friend.
  2. Create two multisets:
    from random import randint
    s0 = [randint(1, 100) for x in xrange(20)]
    s1 = [randint(1, 100) for x in xrange(20)]
    
    Use a list comprehension to compute their set intersection. Use a dictionary to compute their set union.

    Python has a set type. Use it to check your results. Hint: lists and sets are not directly comparable, so you'll need to explicitly bridge the gap --- the list or set constructor might be useful here.

  3. Undergrad and Grad: Compute all primes up to 100. First, do this in whatever way seems most natural to you, but without using a list comprehension. Second, do it in one line using a list comprehension, with an emphasis on clarity, not cleverness.

    Grad: Write a faster list comprehension (a dictionary might be helpful: you are allowed an extra line of code to initialize it and another to query its state). Compute primes up to 10000 both ways and compare the time. Now you can be (a little) clever.